package ru.usu.gv.graph;

import ru.usu.gv.core.GraphCanvas;
import ru.usu.gv.styles.StyleFacade;
import ru.usu.gv.uicomponents.UIGraph;
import ru.usu.gv.uicomponents.UIVertex;

import javax.vecmath.Point3d;

import java.util.ArrayList;
import java.util.List;

/**
 @author: Sergey Pupyrev 
 Mar 26, 2006
 */
public class Vertex
{
	private int index;
	private List<Vertex> inEdges = new ArrayList<Vertex>();
	private List<Vertex> outEdges = new ArrayList<Vertex>();

	public Vertex()
	{
	}

	public int getIndex()
	{
		return index;
	}

	public void setIndex(int index)
	{
		this.index = index;
	}

	public List<Vertex> getOutEdges()
	{
		return outEdges;
	}

	public List<Vertex> getInEdges()
	{
		return inEdges;
	}

	public int getEdgesSize()
	{
		if (StyleFacade.isDirectedGraph())
		{
			return inEdges.size() + outEdges.size();
		}
		else
		{
			return outEdges.size();
		}
	}

	public Vertex getEdge(int index)
	{
		if (StyleFacade.isDirectedGraph())
		{
			if (outEdges.size() > index)
				return outEdges.get(index);
			else
				return inEdges.get(index - outEdges.size());
		}
		else
		{
			return outEdges.get(index);
		}
	}

	public Point3d getPosition()
	{
		UIVertex uiVertex = findUIVertex();
		return uiVertex.getPosition();
	}

	public void setPosition(Point3d position)
	{
		UIVertex uiVertex = findUIVertex();
		uiVertex.setPosition(position);
	}

	public UIVertex findUIVertex()
	{
		UIGraph uiGraph = GraphCanvas.getInstance().getCurrentGraph();
		return uiGraph.getVertexes().get(index);
	}
	
	@Override
	public String toString()
	{
		return String.valueOf(index);
	}
}
